// 思路：破环成链，每次将两堆合成一堆，起点和终点可以是不同的
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 410;

int f[N][N], g[N][N];
int w[N];
int s[N];

int n;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> w[i];
        w[i + n] = w[i];
    }

    for (int i = 1; i <= 2 * n; ++i)
        s[i] = s[i - 1] + w[i];

    memset(g, 0x3f, sizeof g);
    // memset(f, -0x3f, sizeof f);
    for (int len = 1; len <= n; ++len)
        for (int l = 1; l + len - 1 <= 2 * n; ++l)
        {
            int r = l + len - 1;
            if (l == r)
                g[l][l] = f[l][l] = 0;
            else
                for (int k = l; k < r; ++k)
                {
                    f[l][r] = max(f[l][r], f[l][k] + f[k + 1][r] + s[r] - s[l - 1]);
                    g[l][r] = min(g[l][r], g[l][k] + g[k + 1][r] + s[r] - s[l - 1]);
                    // cout << l << ' ' << r << ' ' << f[l][r] << endl;
                }
        }
    int maxv = 0, minv = 1e9;
    for (int i = 1; i <= n; ++i)
    {
        // cout << f[i][i + n - 1] << ' ';
        maxv = max(maxv, f[i][i + n - 1]);
        minv = min(minv, g[i][i + n - 1]);
    }
    // cout << endl;
    cout << minv << endl
         << maxv << endl;
    return 0;
}